const Clipboard = require('@/utils/clipboard.js')
import recom from '@/components/regionComponent.vue'
export default {
  components: {
    recom
  },
  data() {
    return {
      perList: {
        headportrait: '',
        sex: 0, //0、未设置、1、男 2、女
        birthday: '',
        nickname: '',
        provinceid: '', //省份
        cityid: '', //城市
        province: '', //省份
        city: '', //城市
      }, //个人信息
      ids: ''
    }
  },
  onLoad(e) {
    this.ids = e.id

    // #ifdef H5
    this.$nextTick(() => {
      const btnCopy = new Clipboard('.codename')
      btnCopy.on('success', e => {
        uni.showToast({
          icon: 'none',
          title: '复制成功'
        })
      })
    })
    // #endif
  },
  created() {
    this.ServiceInfomation()
  },
  methods: {
    //个人信息
    async ServiceInfomation() {
      try {
        const res = await this.$api.user.ServiceInfomation({
          accountid: this.ids
        })
        this.perList = res.data
        this.perList.province = res.data.location
      } catch (err) {}
    },
    //跳转详情
    ieClick(type) {
      uni.navigateTo({
        url: '/pages_userModule/incomeExpenditurDetails/incomeExpenditurDetails?ieid=' + type.moneyId
      })
    },
    //保存信息
    preserClick() {
      uni.navigateTo({
        url: '/pages_common/pages_me/settlement/settlement'
      })
    },
    // 复制到剪切板 h5不可复制
    copyCode(value) {
      // #ifndef H5
      uni.setClipboardData({
        data: value,
        success: function() {
          uni.showToast({
            title: '复制成功',
            icon: 'none'
          })
        }
      })
      // #endif
    },
    // 把图片保存到本地 h5不可保存
    saveImgLocal(value) {
      uni.downloadFile({
        url: value,
        success: res => {
          if (res.statusCode === 200) {
            uni.saveImageToPhotosAlbum({
              filePath: res.tempFilePath,
              success: function() {
                uni.showToast({
                  title: '保存成功',
                  icon: 'none'
                })
              },
              fail: function() {
                uni.showToast({
                  title: '保存失败，请稍后重试',
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    },
    //分享微信好友
    goPartner(type) {
      let code = this.perList.invitecode
      console.log(code)
      uni.share({
        provider: 'weixin',
        scene: type,
        type: 0,
        summary: '在吗？100%纯羊毛等你来薅哟~',
        title: '送1000元购车抵用券+39元免费洗车券！点击领取吧',
        href: 'https://files.yzsheng.com/shareH5/Qmc_Client_H5/index.html?code=' + code, //这地址太长了，就省略了
        imageUrl: 'https://files.yzsheng.com/client/me/img/logo.png',
        success: function(res) {
          console.log('success:' + JSON.stringify(res))
        },
        fail: function(err) {
          console.log('fail:' + JSON.stringify(err))
          uni.showToast({
            title: '分享失败'
          })
        }
      })
    },
    onJumpChat() {
      let name = ''
      if(this.perList.name){
        name = `&name=${encodeURIComponent(this.perList.name)}`
      } else {
        name = '&name='
      }
      uni.navigateTo({
        url: `/pages_chat/chat/chat?id=${this.ids}&type=C2C${name}`
      })
    }
  }
}
